//
//  ArticleViewController.m
//  drinkApp
//
//  Created by HexPang on 14/8/10.
//  Copyright (c) 2014年 CnbizMedia. All rights reserved.
//

#import "ArticleViewController.h"
#import "UMSocial.h"
#import <TAlertView.h>
#import "UserInforTableViewController.h"
#import "ForgotPasswordViewController.h"
#import "SubscriptionTableViewController.h"
@interface ArticleViewController ()<UITextFieldDelegate,BDSocialUIDelegate>{
//    int lastOffset;
//    BOOL isWorking;
    UITextField*textf;
    float keyHeight;
    UIButton*FavoriteButton;
    UIButton*shareButton;
    NSString*FavoriteID;
    UIButton*ErrorButton;
    NSString*new_ID;
    BOOL isPinch;
    NSString *TextSize;
}
@property (strong, nonatomic) UIView *FooterView;

@end

@implementation ArticleViewController

- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
   
//    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
//    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    
    NSLog(@"%@",request.URL);
    NSString*string =[NSString stringWithFormat:@"%@",request.URL];
//    登录	LoginView/--
//    注册	SignUpView/--
//    订阅	SubscribeView/--
//    我的订阅	MySubscribeView/--
//    个人资料	MyProfileView/--
    UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    NSLog(@"string -- %@",string);
    if ([string hasPrefix:@"open"]) {

        if ([string hasSuffix:@"LoginView/"]) {
            
            LoginViewController*login=[story instantiateViewControllerWithIdentifier:@"LoginViewController"];
            UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:login];
            [self presentViewController:nav animated:YES completion:nil];
            return YES;
        }
       else if ([string hasSuffix:@"SignUpView/"]){
        
        
        ForgotPasswordViewController*SignUpView=[story instantiateViewControllerWithIdentifier:@"ForgotPasswordViewController"];
        UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:SignUpView];
        [self presentViewController:nav animated:YES completion:nil];
        return YES;
        }
        else if ([string hasSuffix:@"SubscribeView/"]){
        
            SubscriptionTableViewController*Subscription=[story instantiateViewControllerWithIdentifier:@"SubscriptionTableViewController"];
            UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:Subscription];
            [self presentViewController:nav animated:YES completion:^{
                [Subscription Set_segmented:NO];
            }];
            return YES;
        }else if ([string hasSuffix:@"MySubscribeView/"]){
            SubscriptionTableViewController*Subscription=[story instantiateViewControllerWithIdentifier:@"SubscriptionTableViewController"];
            UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:Subscription];
            [self presentViewController:nav animated:YES completion:^{
                [Subscription Set_segmented:YES];
            }];
            return YES;
        }
        else if ([string hasSuffix:@"MyProfileView/"]){
           
            UserInforTableViewController*UserInfor=[story instantiateViewControllerWithIdentifier:@"UserInforTableViewController"];
            UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:UserInfor];
            [self presentViewController:nav animated:YES completion:nil];
            return YES;
        }

    }

    return YES;
}

- (void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    
//    [SVProgressHUD showErrorWithStatus:LOADING_TEXT_ERROR];
//    [SVProgressHUD dismiss];
//    ErrorButton=[UIButton buttonWithType:UIButtonTypeCustom];
//    [ErrorButton setImage:[UIImage imageNamed:@"article_logo"] forState:UIControlStateNormal];
//    [ErrorButton setFrame:webView.frame];
//    [ErrorButton addTarget:self action:@selector(webViewReload) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:ErrorButton];
}

- (void)webViewDidStartLoad:(UIWebView *)webView{
    
    
    [self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"doNewsContentLabel(%@)",TextSize]];
//    [webView setUserInteractionEnabled:NO];
    //[SVProgressHUD showWithStatus:LOADING_TEXT maskType:SVProgressHUDMaskTypeGradient];
}
-(void)webViewReload{
//    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self._Dict[@"url"]]]];
    [self.webView reload];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
    [SVProgressHUD dismiss];
     [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    [self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"doNewsContentLabel(%@)",TextSize]];
    [ErrorButton removeFromSuperview];
    [self getIsFavorite];

}
-(void)getIsFavorite{
    NSString*str=[self.webView stringByEvaluatingJavaScriptFromString:@"getFavorite();"];
    NSLog(@"self.webView == %@",self.webView);
    NSLog(@"str == %@",str);
    if ([str integerValue]==0) {
        FavoriteID=@"0";
        [FavoriteButton setImage:[UIImage imageNamed:@"news_04"] forState:UIControlStateNormal];
    }else{
        FavoriteID=str;
        [FavoriteButton setImage:[UIImage imageNamed:@"news_05"] forState:UIControlStateNormal];
    }
}
-(void)theFavoriteYes{
    [FavoriteButton setImage:[UIImage imageNamed:@"news_05"] forState:UIControlStateNormal];
}

- (void)setShareButtonHide:(BOOL)isHide{
    /*
    if(isWorking) return;
    if(isHide){
        isWorking = YES;
        [UIView animateWithDuration:0.5f animations:^{
            [self.shareButton setFrame:CGRectMake(-self.shareButton.frame.size.width, self.shareButton.frame.origin.y, self.shareButton.frame.size.width, self.shareButton.frame.size.height)];
        } completion:^(BOOL finished) {
            isWorking = NO;
            [self.shareButton setHidden:YES];
        }];
    }else{
        //16
        isWorking = YES;
        [self.shareButton setHidden:NO];
        [UIView animateWithDuration:0.5f animations:^{
            [self.shareButton setFrame:CGRectMake(16, self.shareButton.frame.origin.y, self.shareButton.frame.size.width, self.shareButton.frame.size.height)];
        } completion:^(BOOL finished) {
            isWorking = NO;
        }];
    }*/
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    /*
    int offset = [[self.webView stringByEvaluatingJavaScriptFromString:@"window.pageYOffset"] intValue];
    if(lastOffset != 0){
        if(offset > lastOffset){
            if(!self.shareButton.isHidden){
                [self setShareButtonHide:YES];
            }
        }else if(lastOffset > offset){
            if(self.shareButton.isHidden){
                [self setShareButtonHide:NO];
            }
        }
    }else{
        if(self.shareButton.isHidden){
            [self setShareButtonHide:NO];
        }
    }
    lastOffset = offset;*/
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [SVProgressHUD show];
    
    NSLog(@"0isCommentVC yesOrNo -- %hhd",_isCommentVC);
    

    self.webView.scrollView.delegate = self;
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    [self URLgetID];
    
    [self registerForKeyboardNotifications];
    UILabel*label=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 20)];
    label.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:label];
    NSString*url=self._Dict[@"url"];
    if (url.length<5) {
        url=self._Dict[@"content"];
    }
    NSMutableURLRequest *requestM = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:url]];
    [requestM addValue:[AppAPIClient sharedClient].cookie forHTTPHeaderField:[AppAPIClient sharedClient].name];
    [requestM addValue:[UIDevice currentDevice].name forHTTPHeaderField:@"X-Device-Name"];
    [requestM addValue:[OpenUDID_UDID value] forHTTPHeaderField:@"X-Device-UDID"];
    NSString *token = [[NSUserDefaults standardUserDefaults] valueForKey:@"token"];
    if (token) {
        [requestM addValue:token forHTTPHeaderField:@"X-Token-Val"];
    }
    NSString *cookie = [AppAPIClient sharedClient].cookie;
    
    cookie = [NSString stringWithFormat:@"%@=%@",[AppAPIClient sharedClient].name,cookie];
//    NSLog(@"Cookie:%@",cookie);
    [requestM addValue:cookie forHTTPHeaderField:@"Cookie"];
//    NSLog(@"Token:%@,Cookie:%@ - %@",token,[AppAPIClient sharedClient].cookie,[AppAPIClient sharedClient].name);
    requestM = [requestM copy];
    [self.webView loadRequest:[requestM copy]];//webView加载网页
    
    isPinch = NO;
    TextSize = [UserDefaults objectForKey:@"TextSize"];
    if ([TextSize floatValue]<17) {
        [UserDefaults setObject:@"17" forKey:@"TextSize"];
        TextSize = @"17";
    }
    ////添加返回手势
    UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
    [[self view] addGestureRecognizer:recognizer];
    
    NSLog(@"01isCommentVC yesOrNo -- %hhd",_isCommentVC);
}
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{

    if(recognizer.direction==UISwipeGestureRecognizerDirectionRight) {
        CATransition*transition=[CATransition animation];
        transition.duration=1;
        transition.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        transition.type=kCATransitionPush;
        transition.subtype=kCATransitionFromLeft;//方向
        [self.view.layer addAnimation:transition forKey:nil];
        [self dismissViewControllerAnimated:YES completion:^{
            [SVProgressHUD dismiss];
        }];

    }
}
-(void)URLgetID{
    if (![self._Dict isKindOfClass:[NSDictionary class]]) {
        [self dismissViewControllerAnimated:YES completion:^{
        return;
        }];
    }
    NSString*type=[NSString stringWithFormat:@"%@",self._Dict[@"type"]];
    if ([type isEqualToString:@"ad"]) {
        return;
    }else if ([type isEqualToString:@"custom"]){
        return;
    }
    NSString*url=self._Dict[@"url"];
    if (url.length<5) {
        url=self._Dict[@"content"];
    }
    NSArray*ksjv2=[url componentsSeparatedByString:@"ksjv2.kanshangjie.com"];
    if (ksjv2.count<2) {
        return;
    }
    NSArray *arr = [url componentsSeparatedByString:@"?"];
    NSArray*arr2=[arr[1] componentsSeparatedByString:@"&"];
    for (NSString*str in arr2) {
        NSArray*strA=[str componentsSeparatedByString:@"="];
        if ([strA[0] isEqualToString:@"id"]) {
            new_ID=strA[1];
            break;
        }
    }

}


//显示下方的按钮条
-(void)setIsCommentVC:(BOOL)isCommentVC{
    self.FooterView=[[UIView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height-40, self.view.frame.size.height, 40)];
    self.FooterView.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:self.FooterView];
    UILabel*label=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0.5)];
    label.backgroundColor=UIColorFromRGB(0xcccccc);
    [self.FooterView addSubview:label];///分割线
    
    NSLog(@"isCommentVC yesOrNo -- %hhd",isCommentVC);
    if (isCommentVC) {
        UIButton*backbutton=[UIButton buttonWithType:UIButtonTypeCustom];
        [backbutton setFrame:CGRectMake(5, 5, 40, 30)];
        [backbutton setImage:[UIImage imageNamed:@"news_01"] forState:UIControlStateNormal];
        [backbutton addTarget:self action:@selector(backButton:) forControlEvents:UIControlEventTouchUpInside];
        [self.FooterView addSubview:backbutton];
        UILabel * leftView3 = [[UILabel alloc] initWithFrame:CGRectMake(10,0,10,26)];
        leftView3.backgroundColor = [UIColor clearColor];
        
        textf=[[UITextField alloc]initWithFrame:CGRectMake(45, 5, self.view.frame.size.width-50-70, 30)];
        textf.leftView = leftView3;
        textf.leftViewMode = UITextFieldViewModeAlways;
        textf.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        textf.placeholder=@"说点什么吧";
        textf.delegate=self;
        textf.tag=123;
        textf.returnKeyType=UIReturnKeyDone;
        textf.backgroundColor=[UIColor colorWithWhite:0.969 alpha:1.000];
        textf.layer.borderWidth=0.5;
        textf.layer.borderColor=[UIColor lightGrayColor].CGColor;
        [textf.layer setCornerRadius:5];
        [textf.layer setMasksToBounds:YES];
    
        [self.FooterView addSubview:textf];
        UIButton*button=[UIButton buttonWithType:UIButtonTypeCustom];
        [button setFrame:CGRectMake(textf.frame.size.width+textf.frame.origin.x+10, 5, 50, 30)];
        [button setBackgroundColor:[UIColor redColor]];
        [button setTitle:@"发送" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        button.layer.cornerRadius = 5;
        button.layer.masksToBounds = YES;
        [button addTarget:self action:@selector(AddComment) forControlEvents:UIControlEventTouchUpInside];
        [self.FooterView addSubview:button];
    }else{
        [[[UIImageView alloc]init] sd_setImageWithURL:[NSURL URLWithString:self._Dict[@"thumb"]]];
        UIPinchGestureRecognizer*pinch=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinch:)];
        [self.webView addGestureRecognizer:pinch];
        float size =self.view.frame.size.width/4;
        for (long int i=0; i<4; i++) {
            UIButton*button=[UIButton buttonWithType:UIButtonTypeCustom];
            [button setFrame:CGRectMake(size*i, 0, size, 40)];
            switch (i) {
                    
                    //添加下面的四个按钮
                case 0:
                    [button setImage:[UIImage imageNamed:@"news_01"] forState:UIControlStateNormal];
                    [button addTarget:self action:@selector(backButton:) forControlEvents:UIControlEventTouchUpInside];
                    break;
                case 1:
                    [button setImage:[UIImage imageNamed:@"news_02"] forState:UIControlStateNormal];
                    [button addTarget:self action:@selector(shareTouched:) forControlEvents:UIControlEventTouchUpInside];
                    shareButton=button;
                    break;
                case 2:
                    [button setImage:[UIImage imageNamed:@"news_03"] forState:UIControlStateNormal];
                    if ([new_ID integerValue]<=0) {
                        break;
                    }
                    [button addTarget:self action:@selector(Comment:) forControlEvents:UIControlEventTouchUpInside];
                    break;
                case 3:
                    [button setImage:[UIImage imageNamed:@"news_04"] forState:UIControlStateNormal];
                    if ([new_ID integerValue]<=0) {
                        break;
                    }
                    [button addTarget:self action:@selector(Favorite:) forControlEvents:UIControlEventTouchUpInside];
                    FavoriteButton=button;
                    break;
                    
                default:
                    break;
            }
            [self.FooterView addSubview:button];
        }
    }
    _isCommentVC=isCommentVC;
}
-(void)pinch:(UIPinchGestureRecognizer *)recognizer{
    if (isPinch) {
        return;
    }
    if (recognizer.scale>2.0) {
        if ([TextSize intValue]>=21) {
            return;
        }
        TextSize=[NSString stringWithFormat:@"%d",[TextSize intValue]+2];
        
        [SVProgressHUD showSuccessWithStatus:@"字体增大"];
        isPinch = YES;
        [self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"doNewsContentLabel(%@)",TextSize]];
        [self performSelector:@selector(isPinchBuff) withObject:nil afterDelay:0.2];
    }else if (recognizer.scale<0.6){
        if ([TextSize intValue]<=13) {
            return;
        }
        TextSize=[NSString stringWithFormat:@"%d",[TextSize intValue]-2];
        [SVProgressHUD showSuccessWithStatus:@"字体减小"];
        isPinch = YES;
        [self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"doNewsContentLabel(%@)",TextSize]];
        [self performSelector:@selector(isPinchBuff) withObject:nil afterDelay:0.2];
    }

}
-(void)isPinchBuff{
    isPinch=NO;
}
-(void)viewDidDisappear:(BOOL)animated{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    [UserDefaults setObject:TextSize forKey:@"TextSize"];
}
-(void)AddComment{
    if (IFUserLogin) {
        if (textf.text.length>2) {
            
        [SVProgressHUD showWithStatus:@"评论发布中..." maskType:SVProgressHUDMaskTypeClear];
     [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
    [[AppAPIClient sharedClient] POST:@"Comment/Add" parameters:@{@"id":new_ID,@"cateid":self._Dict[@"catid"],@"content":textf.text} success:^(AFHTTPRequestOperation *operation, id responseObject) {
        textf.text=@"";
        [SVProgressHUD showSuccessWithStatus:@"评论成功"];
        [self performSelector:@selector(webViewReload) withObject:nil afterDelay:0];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"ERR: %@",operation.responseString);
        
    }];
        }else{
            [SVProgressHUD showErrorWithStatus:@"评论过短"];
        }
    }else{
        UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        LoginViewController*login=[story instantiateViewControllerWithIdentifier:@"LoginViewController"];
        UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:login];
//        [self.navigationController pushViewController:login animated:YES];
        [self presentViewController:nav animated:YES completion:nil];
    }
}
-(void)viewDidLayoutSubviews{

    self.webView.frame=CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y+20, self.view.frame.size.width, self.view.frame.size.height-60);
    
    self.FooterView.frame=CGRectMake(0, self.view.frame.size.height-40, self.view.frame.size.width, 40);
    long int size=self.view.frame.size.width/4;
    
    for (int i =0; i<4; i++) {
        UIButton*button=(UIButton*)[self.FooterView viewWithTag:i+1];
        CGRect frame =CGRectMake(i*size, button.frame.origin.y, size, button.frame.size.height);
        [button setFrame:frame];
        [button setNeedsDisplay];
        [button setNeedsLayout];
    }


}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}
- (void)backButton:(id)sender {
    [SVProgressHUD dismiss];
    if (self.webView.canGoBack) {
        [self.webView goBack];
    }else{
        [self dismissViewControllerAnimated:YES completion:^{
//            [self.webView goBack];
        }];
        
        
    }
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}
-(void)textFieldDidBeginEditing:(UITextField *)textField{
    [UIView animateWithDuration:.3 animations:^{
        self.view.frame=CGRectMake(0, -30, self.view.frame.size.width, self.view.frame.size.height);
         }];
    
}
-(void)textFieldDidEndEditing:(UITextField *)textField{
        [UIView animateWithDuration:.3 animations:^{
            self.FooterView.frame=CGRectMake(0, self.FooterView.frame.origin.y+keyHeight, self.FooterView.frame.size.width, self.FooterView.frame.size.height);
            self.view.frame=CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
            
        }];
}
- (void) registerForKeyboardNotifications

{
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];
    
    
    
    [[NSNotificationCenter defaultCenter]  addObserver:self selector:@selector(keyboardWasHidden:) name:UIKeyboardDidHideNotification object:nil];
}


- (void) keyboardWasShown:(NSNotification *) notif

{

    NSDictionary *info = [notif userInfo];
    
    NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
    
    CGSize keyboardSize = [value CGRectValue].size;
    
    if (keyboardSize.height>keyHeight) {
        keyHeight=keyboardSize.height-30;
    }

    NSLog(@"keyBoard:%f", keyboardSize.height);  //216
    [UIView animateWithDuration:0 animations:^{
        self.FooterView.frame=CGRectMake(0, self.view.frame.size.height-keyHeight-self.FooterView.frame.size.height, self.FooterView.frame.size.width, self.FooterView.frame.size.height);
        
    }];
    ///keyboardWasShown = YES;
    
}

- (void) keyboardWasHidden:(NSNotification *) notif

{
    
    NSDictionary *info = [notif userInfo];
    
    
    
    NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
    
    CGSize keyboardSize = [value CGRectValue].size;
    
    NSLog(@"keyboardWasHidden keyBoard:%f", keyboardSize.height);
    [UIView animateWithDuration:0 animations:^{
        self.FooterView.frame=CGRectMake(0, self.view.frame.size.height-self.FooterView.frame.size.height, self.FooterView.frame.size.width, self.FooterView.frame.size.height);
    }];
    
    
    
}
- (void)shareTouched:(id)sender{
    [SVProgressHUD show];
    NSLog(@"description -- %@",self._Dict[@"description"]);//self._Dict[@"description"]
    NSString *description = [UserDefaults objectForKey:@"description"];
    NSLog(@"description ==--+++%@",description);
    
    
    NSString *des = self._Dict[@"description"];//简介
    if (des.length == 0) {
        des = self._Dict[@"title"];
    }
    
    BDSocialShareContent *content = [BDSocialShareContent shareContentWithDescription:self._Dict[@"title"] url:self._Dict[@"url"] title:des];
    [content addImageWithThumbImage:[UIImage imageNamed:@"icon_default_ipad"] imageUrl:self._Dict[@"thumb"]];
    UIImageView*imageview=[[UIImageView alloc]init];
    [imageview sd_setImageWithURL:[NSURL URLWithString:self._Dict[@"sharepic"]] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        if (image==nil) {
            [content addImageWithThumbImage:[UIImage imageNamed:@"icon_default_ipad"] imageSource:[UIImage imageNamed:@"icon_default_ipad"]];
        }else{
            [content addImageWithThumbImage:image imageSource:image];
        }
        
        NSLog(@"content == %@",content);

        [SVProgressHUD dismiss];
        
//分享  ,self._Dict[@"url"]  self._Dict[@"title"]    ,self._Dict[@"description"] [NSString stringWithFormat:@"bigbig sb"]
        [UMSocialSnsService presentSnsIconSheetView:self
                                             appKey:nil
                                          shareText:self._Dict[@"title"]
                                         shareImage:imageview.image
                                    shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToQQ,UMShareToQzone,UMShareToWechatTimeline,UMShareToWechatSession,UMShareToEmail,UMShareToSms,UMShareToTencent,nil]
                                           delegate:self];
        
        [UMSocialData defaultData].extConfig.sinaData.urlResource.url = self._Dict[@"url"];
        [UMSocialData defaultData].extConfig.qqData.url = self._Dict[@"url"];
        [UMSocialData defaultData].extConfig.qzoneData.url = self._Dict[@"url"];
        [UMSocialData defaultData].extConfig.wechatTimelineData.url = self._Dict[@"url"];
        [UMSocialData defaultData].extConfig.wechatSessionData.url = self._Dict[@"url"];
        
        
//        [UMSocialData defaultData].extConfig.qqData.title = self._Dict[@"description"];
        
        [UMSocialConfig hiddenNotInstallPlatforms:@[UMShareToQQ,UMShareToQzone,UMShareToWechatSession,UMShareToWechatTimeline]];
        
    }];
    
 
    UMSocialSnsPlatform *sinaPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToTencent];
    sinaPlatform.bigImageName = @"moreButton";
    sinaPlatform.displayName = @"更多";
    sinaPlatform.snsClickHandler = ^(UIViewController *presentingController, UMSocialControllerService * socialControllerService, BOOL isPresentInController){
        NSLog(@"点击更多的响应");
        
        
        NSString *textToShare = [NSString stringWithFormat:@"%@", self._Dict[@"title"] ];
        
        //            UIImage *imageToShare = [UIImage imageNamed:@"iosshare.jpg"];
        
        NSURL *urlToShare = [NSURL URLWithString:self._Dict[@"url"]];
        
        NSArray *activityItems = @[textToShare, imageview, urlToShare];
        
        UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems
                                                
                                                                                applicationActivities:nil];
        
        
        
        //不出现在活动项目
        
        activityVC.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard,
                                             
                                             UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll];
        
        [self presentViewController:activityVC animated:TRUE completion:nil];
        
    };

}

-(void)didSelectSocialPlatform:(NSString *)platformName withSocialData:(UMSocialData *)socialData
{
    if (platformName == UMShareToSina) {
        socialData.shareText = [NSString stringWithFormat:@"%@ %@ %@",self._Dict[@"title"],self._Dict[@"description"],self._Dict[@"url"]];
    }
    else{
        socialData.shareText = [NSString stringWithFormat:@"%@",self._Dict[@"description"] ];
        
        
//        QQ设置title方法为
        
        [UMSocialData defaultData].extConfig.qqData.title = self._Dict[@"title"];
        
//        Qzone设置title方法将平台参数名替换即可
        
        [UMSocialData defaultData].extConfig.qzoneData.title = self._Dict[@"title"];
        
        
        
//        设置微信好友title方法为
        
        [UMSocialData defaultData].extConfig.wechatSessionData.title = self._Dict[@"title"]  ;//self._Dict[@"title"]
        
//        设置微信朋友圈title方法替换平台参数名即可
        
        [UMSocialData defaultData].extConfig.wechatTimelineData.title = self._Dict[@"title"];

    }
}
/**
 *	@brief	将要展示分享视图
 *
 *	@param 	viewType       分享视图的类型
 */
- (void)socialUIWillShow:(BD_SOCIAL_VIEW_TYPE)viewType{
   
}

/**
 *	@brief	将要关闭分享视图
 *
 *	@param 	viewType       分享视图的类型
 */
- (void)socialUIWillClose:(BD_SOCIAL_VIEW_TYPE)viewType{
    
}

/**
 *	@brief	分享视图展示完成
 *
 *	@param 	viewType       分享视图的类型
 */
- (void)socialUIDidShow:(BD_SOCIAL_VIEW_TYPE)viewType{
    if (viewType==BD_SOCIAL_VIEW_SHAREMENU) {
        
    }
}

/**
 *	@brief	分享视图关闭完成
 *
 *	@param 	viewType       分享视图的类型
 */
- (void)socialUIDidClose:(BD_SOCIAL_VIEW_TYPE)viewType{

}


//评论按钮点击事件
- (void)Comment:(id)sender{
    if ([self._Dict[@"type"] isEqualToString:@"ad"]) {
        return;
    }else if ([self._Dict[@"type"] isEqualToString:@"custom"]){
        return;
    }
    UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    ArticleViewController*art=[story instantiateViewControllerWithIdentifier:@"ArticleViewController"];
    art._Dict=@{@"id":new_ID,@"catid":self._Dict[@"catid"],@"url":[NSString stringWithFormat:@"http://ksjv2.kanshangjie.com/Comment/Show?cateid=%@&id=%@",self._Dict[@"catid"],new_ID],@"title":self._Dict[@"title"]};
    art.isCommentVC=YES;
    art.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentViewController:art animated:YES completion:nil];

}

//点击收藏按钮
- (void)Favorite:(id)sender{
    if ([self._Dict[@"type"] isEqualToString:@"ad"]) {
        return;
    }else if ([self._Dict[@"type"] isEqualToString:@"custom"]){
        return;
    }
    if (IFUserLogin) {

        NSLog(@"FavoriteID == %@",FavoriteID);
        
        if ([FavoriteID integerValue]==0) {
    NSDictionary*dic=[NSDictionary dictionaryWithObjectsAndKeys:self._Dict[@"title"],@"title",self._Dict[@"url"],@"url", nil];
    [[AppAPIClient sharedClient] GET:@"Favorite/Add" parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [SVProgressHUD showSuccessWithStatus:@"收藏成功"];
        [FavoriteButton setImage:[UIImage imageNamed:@"news_05"] forState:UIControlStateNormal];
        NSString*str=[self.webView stringByEvaluatingJavaScriptFromString:@"getFavorite();"];
        FavoriteID=str;

//                [self performSelector:@selector(webViewReload) withObject:nil afterDelay:3];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"ERR: %@",operation.responseString);

    }];
        }
        else{
            [[AppAPIClient sharedClient] GET:@"Favorite/Remove" parameters:@{@"fid": FavoriteID} success:^(AFHTTPRequestOperation *operation, id responseObject) {
                [SVProgressHUD showSuccessWithStatus:@"删除收藏"];
                [FavoriteButton setImage:[UIImage imageNamed:@"news_04"] forState:UIControlStateNormal];
                FavoriteID=@"0";
                
//                [self performSelector:@selector(webViewReload) withObject:nil afterDelay:3];
            } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                NSLog(@"ERR: %@",operation.responseString);
                
            }];
            
            
        }
    }
    
    //没有登录，跳转到登录界面
    else{
        UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        LoginViewController*login=[story instantiateViewControllerWithIdentifier:@"LoginViewController"];
        UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:login];
        //        [self.navigationController pushViewController:login animated:YES];
        
        [self presentViewController:nav animated:YES completion:nil];
    }
}
#pragma mark - alertView
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
        if (buttonIndex==1) {
            UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
            LoginViewController*login=[story instantiateViewControllerWithIdentifier:@"LoginViewController"];
            [self.navigationController pushViewController:login animated:YES];
        }
}
- (void)viewWillDisappear:(BOOL)animated{
     [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
    //MainView
    [MobClick endLogPageView:@"ArticleView"];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:INNER_NOTIFICATION object:nil];
//    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
- (void) notificationRecv:(NSNotification*)notification{
    NSLog(@"%@",notification.userInfo);
    TAlertView*taler=[[TAlertView alloc]initWithTitle:notification.userInfo[@"title"] message:notification.userInfo[@"description"] buttons:@[@"取消",@"查看"] andCallBack:^(TAlertView *alertView, NSInteger buttonIndex) {
        if (buttonIndex==1) {
            UIStoryboard*story= self.storyboard;
            ArticleViewController*art=[story instantiateViewControllerWithIdentifier:@"ArticleViewController"];
            art._Dict=notification.userInfo;
            art.isCommentVC=NO;
            art.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
            [self presentViewController:art animated:YES completion:nil];
        }
    }];
    taler.timeToClose=5.0;
    taler.buttonsAlign = TAlertViewButtonsAlignHorizontal;
    [taler showAsMessage];
}

- (void)viewWillAppear:(BOOL)animated{
//    if (self.isCommentVC) {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationRecv:) name:INNER_NOTIFICATION object:nil];
//        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
//    }else{
//        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
//    }
    [MobClick beginLogPageView:@"ArticleView"];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
